// Created by WXX on 2021/10/19 14:26
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<string> uncommonFromSentences(string s1, string s2) {
        unordered_map<string, int> hash1, hash2;
        get_words(s1, hash1), get_words(s2, hash2);

        vector<string> res;
        for (auto &[k, v] : hash1)
            if (v == 1 && !hash2.count(k))
                res.push_back(k);
        for (auto &[k, v] : hash2)
            if (v == 1 && !hash1.count(k))
                res.push_back(k);
        return res;
    }

    void get_words(string s, unordered_map<string, int> &mp) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == ' ') continue;
            int j = i + 1;
            while (j < s.size() && s[j] != ' ') j++;
            mp[s.substr(i, j - i)]++;
            i = j;
        }
    }
};

void OutputBasicArray1D(vector<string> nums) {
    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << nums[i];
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    string A = "this apple is sweet", B = "this apple is sour";
    OutputBasicArray1D(Solution().uncommonFromSentences(A, B));

    return 0;
}
